<!--
 * @Author: SonLight Tech
 * @Date: 2023-04-18 16:07:53
 * @LastEditors: light
 * @LastEditTime: 2023-04-19 10:00:39
 * @Description: SonLight Tech版权所有
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>微信支付</title>



    <style>
        .btn {
            border-radius: 2px;
            outline: none;
            background: #07c160;
            border: unset;
            padding: 0px 15px;
            margin: 0px auto;
            margin-left: 50%;
            transform: translateX(-50%);
            margin-top: 10%;
            line-height: 36px;
            color: white;
            font-size: 16px;
        }
    </style>
</head>

<body>


    <button class="btn">jsapi支付0.01元测试</button>

    <script>

        function onBridgeReady() {
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest', {
                "appId": "{$data['appId']}",     //公众号ID，由商户传入
                "timeStamp": "{$data['timeStamp']}",         //时间戳，自1970年以来的秒数
                "nonceStr": "{$data['nonceStr']}", //随机串
                "package": "{$data['package']}",
                "signType": "{$data['signType']}",         //微信签名方式：
                "paySign": "{$data['paySign']}" //微信签名
            },
                function (res) {
                    console.log(res);
                    if (res.err_msg == "get_brand_wcpay_request:ok") {
                        // 使用以上方式判断前端返回,微信团队郑重提示：
                        //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
                    }
                });
        }

        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        } else {
            onBridgeReady();
        }

    </script>
</body>

</html>